package org.zhou.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.zhou.pojo.Administrator;
import org.zhou.pojo.Book;
import org.zhou.pojo.Readers;

import java.util.List;

@Mapper
public interface AdminMapper {

    /**
     * 根据用户名查询管理员
     * @param username
     * @return
     */
    @Select("select * from administrator where username = #{username}")
    Administrator getByUsername(String username);

    /**
     * 修改基本信息
     * @param admin
     */
    void updateInfo(Administrator admin);

    @Update("update administrator set password = #{newPwd} where id = #{id}")
    void updatePwd(String newPwd, Integer id);

    /**
     * 查询读者
     * @param name
     * @param state
     * @param phone
     * @param readerId
     * @return
     */
    List<Readers> readerList(String name, Integer state, String phone, String readerId);

    /**
     * 添加读者
     * @param readers
     */
    @Insert("insert into readers ( name, id_number, phone, balance, status) VALUES " +
            "(#{name},#{idNumber},#{phone},#{balance},#{status})")
    void addReader(Readers readers);

    @Update("update readers set name=#{name},id_number=#{idNumber},phone=#{phone},balance=#{balance},status=#{status} " +
            "where id=#{id}")
    void updateReader(Readers readers);

    @Insert("insert into administrator ( name, username, password ) values " +
            "(#{username},#{username},#{password})")
    void addAdmin(String username, String password);

    @Update("update administrator set status=#{status} where username=#{username}")
    void updateStatus(Integer status,String username);
}
